<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let persons = [
            { "username": "xiaoming1", "password": "1111" },
            { "username": "xiaoming2", "password": "222" },
            { "username": "xiaoming3", "password": "33333" }
        ]
        let user = { username: "admin1", password: "12345" }
        // let user = { username: "xiaoming1", password: "12345" }

        //登录
        var v = persons.find(item => user.username === item.username && user.password === item.password)
        if (v) {
            console.log('登录成功');
        } else {
            console.log('用户名和密码错误');
        }
 
        console.log(v);

        //注册
        var s = persons.find(item => user.username === item.username)
        if (s) {
            console.log('您已经注册过了，可以登录！');
        } else {
            persons.push(user);
        }
        console.log(persons);
     
       // 登录原理：
       //     如果persons中含有对应的用户名和密码则提示登录成功，否则提示用户名和密码错误
       // 注册原理：
       //     如果persons中没有对应的用户，则把user追加到persons末尾
    </script>
</body>

</html>